// src/services/replyService.js
import apiClient from './api'

/**
 * 根据帖子 ID 分页获取回复列表 (支持嵌套结构)
 * @param {number} postId - 帖子 ID
 * @param {Object} params - 查询参数 (page, size, sort 等)
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getRepliesByPostId = async (postId, params = {}) => {
  return await apiClient.get(`/posts/${postId}/replies`, { params })
}

/**
 * 发表新回复
 * @param {Object} replyData - 回复数据 { content, postId, parentId (可选) }
 * @returns {Promise<AxiosResponse<any>>}
 */
export const createReply = async (replyData) => {
  return await apiClient.post('/replies', replyData)
}

/**
 * 更新回复
 * @param {number} id - 回复 ID
 * @param {Object} replyData - 更新的回复数据 { content }
 * @returns {Promise<AxiosResponse<any>>}
 */
export const updateReply = async (id, replyData) => {
  return await apiClient.put(`/replies/${id}`, replyData)
}

/**
 * 删除回复
 * @param {number} id - 回复 ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const deleteReply = async (id) => {
  return await apiClient.delete(`/replies/${id}`)
}

/**
 * 点赞回复
 * @param {number} id - 回复 ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const likeReply = async (id) => {
  return await apiClient.post(`/replies/${id}/like`)
}

/**
 * 取消点赞回复
 * @param {number} id - 回复 ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const unlikeReply = async (id) => {
  return await apiClient.delete(`/replies/${id}/like`)
}
